import { defineStore } from 'pinia'
import request from '../utils/request'
import { IArticleItem, IResponse } from '../types/data'

export default defineStore('newslist', {
  state: () => ({
    newsList: [] as IArticleItem[],
  }),
  actions: {
    // 准备一个根据频道 ID 获取新闻的方法 action
    async getNewsList(id: number) {
      const r = await request<
        IResponse<{
          results: IArticleItem[]
          pre_timestamp: string
        }>
      >(`/articles?channel_id=${id}&timestamp=${Date.now()}`)
      // r.data
      // r.data.data.results[0].art_id
      this.newsList = r.data.data.results
    },
  },
})
